
from flask import Flask, request, jsonify
from major import *

MC = mc.MysqlConn()

app = Flask(__name__)
# 获取今日新闻
@app.route('/today', methods=['GET'])
def api_get_today_news():
    return jsonify(get_totay_news())

# 获取新闻详情
@app.route('/detail', methods=['GET'])
def api_get_news_by_id():
    news_id = request.args.get('id', '')
    return jsonify(get_news_by_id(news_id))

# 搜索新闻
@app.route('/query', methods=['POST'])
def api_search_news():
    query = request.json.get('query', '今日新闻')
    return search_news(query)



if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5887)